define('commentInstallTrain', function(require, exports, module) {
	var view = function(id){
		var self = this;
		$.get(contextPath + '/commentInstallTrain/update/'+id).done(function(html){
			addBreadcrumbMenu('查看');
			pageContents.html(html);
			init('view',id);
		});
	};
	var add = function(){
		var self = this;
		$.get(contextPath + '/commentInstallTrain/new').done(function(html){
			addBreadcrumbMenu('新增');
			pageContents.html(html);
			init('add');
		});
	};
	var modify = function(id){
		var self = this;
		$.get(contextPath + '/commentInstallTrain/update/'+id).done(function(html){
			addBreadcrumbMenu('修改');
			pageContents.html(html);
			init('modify', id);
		});
	};
	var init = function(type, id){
		pageContents.find('#returnBtn').on('click', function(){
			var children = breadcrumb.children();
			children[children.length-2].click();
		});
		pageContents.find('#useSatRating').stars({
			id: 'useSat'
		});
		pageContents.find('#customerServiceSatRating').stars({
			id: 'customerServiceSat'
		});
		var form = pageContents.find('#form');
		var saveBtn = pageContents.find('#saveBtn');
		if (type == 'modify') {
			pageContents.find('.panel-title').text('修改评价信息');
			pageContents.find('#useSatRating')
				.find('[data-value="'+pageContents.find('#useSat').val()+'"]')
				.click();
			pageContents.find('#customerServiceSatRating')
				.find('[data-value="'+pageContents.find('#customerServiceSat').val()+'"]')
				.click();
		} else if (type == 'view') {
			pageContents.find('.panel-title').text('查看评价信息');
			pageContents.find('#useSatRating')
				.find('[data-value="'+pageContents.find('#useSat').val()+'"]')
				.click();
			pageContents.find('#customerServiceSatRating')
				.find('[data-value="'+pageContents.find('#customerServiceSat').val()+'"]')
				.click();
			form.find('input, select, textarea').attr('disabled', 'disabled');
			saveBtn.hide();
			return;
		} else {
			pageContents.find('.panel-title').text('新增用户');
		}
		require('util').initValidate(form);
		saveBtn.on('click', function(){
			var form = pageContents.find('#form');
			var $btn = $(this);
			if($btn.hasClass('disabled')){
				form.message({
					type: 'warning',
					content: '请不要重复提交!'
				});
				return;
			}
			$btn.addClass('disabled').attr('disabled', true);
			var util = require('util');
			if (!util.validate(form)) {
				$btn.removeAttr('disabled').removeClass('disabled');
				return;
			}
			var data = util.getFormData(form);
			$.post(contextPath + '/commentInstallTrain/save', data).done(function(data){
				if(data.statusCode == 20011011){
					$('body').message({
						type: 'success',
						content: '保存成功'
					});
					pageContents.find('#returnBtn').click();
				}else{
					pageContents.find('#form').message({
						type: 'error',
						content: data.msg
					});
					$btn.removeAttr('disabled').removeClass('disabled');
				}
			});
		});
	};
	var remove = function(ids, dataGrid){
		var data = {
			delIds: ids.join('@')
		}
		$.post(contextPath + '/commentInstallTrain/delete', data).done(function(data){
			if(data.statusCode == 20011011){
				dataGrid.message({
					type: 'success',
					content: data.msg
				});
				dataGrid.grid('refresh');
			}else{
				dataGrid.message({
					type: 'error',
					content: data.msg
				});
			}
		});
	};
	module.exports = {
		view : view,
		add : add,
		modify : modify,
		remove : remove
	};
});
